//
//  LSWaitForExamineViewController.m
//  LaSaCivilAffairsDepartment
//
//  Created by 聂志康 on 2018/12/24.
//  Copyright © 2018 wpkj. All rights reserved.
//

#import "LSWaitForExamineViewController.h"
#import "LSWaitForExamineTableViewCell.h"
#import "LSWaitForExamineModel.h"
#import "NiWenListCell.h"
#import "LSDaiBanDetailVC.h"
#import "LSContactSelectTableViewModel.h"
#import "LSContactSelectViewController.h"
#import "LSJiaBanDaiBanVC.h"
#define CountPerPage 20

@interface LSWaitForExamineViewController () <UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate, LSWaitForExamineTableViewCellDelegate>
@property (nonatomic, assign) BOOL nwglXialaImageViewIsShowing;
@property (nonatomic, strong) UIImageView *nwglXialaImageView;
@property (nonatomic, strong) UIView *backgroundAlphaView;
@property (nonatomic, strong) NSArray <NSDictionary *> *selectButtonsArray;

@property (nonatomic, assign) int tableViewPage;
@property (nonatomic, strong) UIView *waitForExamineTableViewHeaderView;
@property (nonatomic, strong) UITableView *waitForExamineTableView;
@property (nonatomic, strong) UITextField *categorySelectBeginnerTF;
@property (nonatomic, strong) UITextField *searchInfoTF;
@property (nonatomic, strong) NSMutableArray *dataArrayM;
@property (nonatomic, strong) UIButton *selectAllButton;
@property (nonatomic, strong) UITextField *niWenName;

@property (nonatomic, strong) NZKNoDataView *nodataView;
@property (nonatomic, strong) NZKNetworkErrorView *networkErrorView;

@property (nonatomic, strong) UIView *yzView;
@property (nonatomic, strong) LSContactSelectTableViewModel *selectedContactModel;

//已选中的model
@property (nonatomic, strong) NSDictionary *selectDict;
@property (nonatomic, strong) NSArray *chosenArray;//选中联系人
@end
#define SelectViewWidth (147/3*2)
#define SelectViewHeight (100)
#define headerSearchViewHeight 56
static NSString *LSWaitForExamineTableViewCellID = @"LSWaitForExamineTableViewCellID";

@implementation LSWaitForExamineViewController

- (void)setUpHeaderSearchView {
    UIView *headerSearchView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, headerSearchViewHeight)];
    headerSearchView.backgroundColor = UIColor.whiteColor;
    [self.view addSubview:headerSearchView];
    UIView *headerViewBottomLineView = [[UIView alloc] initWithFrame:CGRectMake(0, headerSearchViewHeight-0.5, ScreenWidth, 0.5)];
    headerViewBottomLineView.backgroundColor = hexColor(CCCCCC);
    [headerSearchView addSubview:headerViewBottomLineView];
    
    // 拟文名
    UITextField *nameTF = [[UITextField alloc] initWithFrame:CGRectMake(15, 5+4, ScreenWidth-30-55-15, 36)];
    self.niWenName = nameTF;
    nameTF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:12];
    nameTF.layer.borderColor = hexColor(dbdbdb).CGColor;
    nameTF.layer.borderWidth = 1;
    nameTF.returnKeyType = UIReturnKeySearch;
    nameTF.placeholder = @"请输入标题";
    nameTF.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 8, 1)];
    nameTF.leftViewMode = UITextFieldViewModeAlways;
    [headerSearchView addSubview:nameTF];
    
    UIButton *searchButton = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-15-55, 9, 55, 36)];
    searchButton.layer.cornerRadius = 4;
    searchButton.layer.masksToBounds = true;
    searchButton.backgroundColor = NAV_COLOR;
    [searchButton setTitle:@"搜索" forState:UIControlStateNormal];
    searchButton.titleLabel.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:12];
    [searchButton addTarget:self action:@selector(loadData) forControlEvents:UIControlEventTouchUpInside];
    [headerSearchView addSubview:searchButton];
}
- (NSArray<NSDictionary *> *)selectButtonsArray {
    if (!_selectButtonsArray) {
        _selectButtonsArray = @[@{@"title":@"  办 理",@"image":@"xinzen"},
                                @{@"title":@"  委 托",@"image":@"banli"}];
    }
    return _selectButtonsArray;
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:YES];
}
- (void)moreBarButtonItemClick {
    [self.view endEditing:YES];
    if (self.nwglXialaImageViewIsShowing) {
        [self.nwglXialaImageView removeFromSuperview];
        [self.backgroundAlphaView removeFromSuperview];
        self.nwglXialaImageViewIsShowing = false;
    } else {
        UIWindow *window = [UIApplication sharedApplication].keyWindow;
        [window addSubview:self.backgroundAlphaView];
        [window addSubview:self.nwglXialaImageView];
        self.nwglXialaImageViewIsShowing = true;
    }
}

- (UIImageView *)nwglXialaImageView {
    if (!_nwglXialaImageView) {
        _nwglXialaImageView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenWidth-1-SelectViewWidth, SafeAreaTopHeight-15, SelectViewWidth, SelectViewHeight)];
        _nwglXialaImageView.image = [UIImage imageNamed:@"nwgl_xiala"];
        _nwglXialaImageView.userInteractionEnabled = true;
        for (int i = 0; i < self.selectButtonsArray.count; i++) {
            UIButton *button  = [[UIButton alloc] initWithFrame:CGRectMake(0, 5+(SelectViewHeight-10)/self.selectButtonsArray.count*i, SelectViewWidth, (SelectViewHeight-10)/self.selectButtonsArray.count)];
            [button setImage:[UIImage imageNamed:self.selectButtonsArray[i][@"image"]] forState:UIControlStateNormal];
            [button setTitle:self.selectButtonsArray[i][@"title"] forState:UIControlStateNormal];
            button.tag = 1000+i;
            [button setTitleColor:hexColor(333333) forState:UIControlStateNormal];
            button.titleLabel.font = [UIFont systemFontOfSize:14];
            [_nwglXialaImageView addSubview:button];
            [button addTarget:self action:@selector(nwglXiaLaBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
        }
    }
    return _nwglXialaImageView;
}

#pragma mark 办理 委托
- (void)nwglXiaLaBtnClicked:(UIButton*)button{
    [self.nwglXialaImageView removeFromSuperview];
    [self.backgroundAlphaView removeFromSuperview];
    self.nwglXialaImageViewIsShowing = false;
    switch (button.tag) {
        case 1000:
        {
            //新增
            if ([self.selectDict allKeys].count == 0) {
                [MBProgressHUD showWarnMessage:@"请选择一条记录！"];
                return;
            }
            if ([[ValidateUtils validateNull:self.selectDict[@"definitionName"]] isEqualToString:@"拟文"]) {
                LSDaiBanDetailVC *lvc = [[LSDaiBanDetailVC alloc]init];
                lvc.dict = self.selectDict;
                lvc.type = 1;
                [self.navigationController pushViewController:lvc animated:YES];
            }else if ([[ValidateUtils validateNull:self.selectDict[@"definitionName"]] isEqualToString:@"阅办流程"]) {
                LSDaiBanDetailVC *lvc = [[LSDaiBanDetailVC alloc]init];
                lvc.dict = self.selectDict;
                lvc.type = 2;
                [self.navigationController pushViewController:lvc animated:YES];
            }else{
                LSJiaBanDaiBanVC *lvc = [[LSJiaBanDaiBanVC alloc]init];
                lvc.dict = self.selectDict;
                [self.navigationController pushViewController:lvc animated:YES];
            }
        }
            break;
        case 1001:
        {
            if ([self.selectDict allKeys].count == 0) {
                [MBProgressHUD showWarnMessage:@"请选择一条记录！"];
                return;
            }
            [self selectYueZhiPerson];
        }
            break;
        default:
            break;
    }
}


- (UIView *)backgroundAlphaView {
    if (!_backgroundAlphaView) {
        _backgroundAlphaView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
        _backgroundAlphaView.backgroundColor = UIColor.clearColor;
        _backgroundAlphaView.userInteractionEnabled = true;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(backgroundAlphaViewTapped)];
        [_backgroundAlphaView addGestureRecognizer:tap];
    }
    return _backgroundAlphaView;
}

- (void)backgroundAlphaViewTapped {
    [self.nwglXialaImageView removeFromSuperview];
    [self.backgroundAlphaView removeFromSuperview];
    self.nwglXialaImageViewIsShowing = false;
}

- (UIView *)yzView{
    if (!_yzView) {
        _yzView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
        _yzView.backgroundColor =hexColorAlpha(000000, 0.5);
        _yzView.userInteractionEnabled = true;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(yzViewTapped)];
        [_backgroundAlphaView addGestureRecognizer:tap];
    }
    
    return _yzView;
}
- (void)yzViewTapped{
    [self.yzView removeFromSuperview];
    for (LSContactSelectTableViewModel *model in self.chosenArray) {
        model.isSelected = false;
    }
    self.chosenArray = @[];
}
- (void)selectYueZhiPerson{
    //    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    [self.tabBarController.view addSubview:self.yzView];
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, (ScreenHeight-(20+30+10+50+10+30+10+10+10))/2.0, ScreenWidth, 20+30+10+50+10+30+10+10+10)];
    view.backgroundColor = hexColor(ffffff);
    [self.yzView addSubview:view];
    UIView *topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 60)];
    topView.backgroundColor = hexColor(ffffff);
    [view addSubview:topView];
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 20, 100, 30)];
    label.textColor = hexColor(333333);
    label.text = @"选择委托人";
    [topView addSubview:label];
    
    UIButton *chooseBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    chooseBtn.frame = CGRectMake(ScreenWidth-20-60-20-60-10, 15, 60, 40);
    chooseBtn.backgroundColor = hexColor(EEEEEE);
    [chooseBtn setTitle:@"选择" forState:UIControlStateNormal];
    [chooseBtn setTitleColor:hexColor(333333) forState:UIControlStateNormal];
    [topView addSubview:chooseBtn];
    
    
    UIButton *clearBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    clearBtn.frame = CGRectMake(ScreenWidth-20-60,15, 60, 40);
    clearBtn.backgroundColor = hexColor(EEEEEE);
    [clearBtn setTitle:@"清空" forState:UIControlStateNormal];
    [clearBtn setTitleColor:hexColor(333333) forState:UIControlStateNormal];
    [topView addSubview:clearBtn];
    
    UILabel *personsLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(topView.frame)+10, ScreenWidth-20, 50)];
    personsLabel.clipsToBounds = YES;
    personsLabel.layer.cornerRadius = 5;
    personsLabel.layer.borderColor = hexColor(A6A6A6).CGColor;
    personsLabel.layer.borderWidth  = 1;
    personsLabel.textColor = hexColor(666666);
    personsLabel.font = [UIFont systemFontOfSize:15];
    [view addSubview:personsLabel];
    personsLabel.tag = 800;
    
    CGFloat maxY = CGRectGetMaxY(personsLabel.frame)+10;
    
    UIButton *quxiaoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    quxiaoBtn.backgroundColor = topView.backgroundColor;
    quxiaoBtn.frame = CGRectMake(ScreenWidth-20-80, maxY, 80, 40);
    [quxiaoBtn setTitle:@"取消" forState:UIControlStateNormal];
    [quxiaoBtn setTitleColor:hexColor(333333) forState:UIControlStateNormal];
    [view addSubview:quxiaoBtn];
    quxiaoBtn.backgroundColor = hexColor(EEEEEE);
    
    UIButton *okBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    okBtn.backgroundColor = topView.backgroundColor;
    okBtn.frame = CGRectMake(ScreenWidth-20-80-20-80-10, maxY, 80, 40);
    [okBtn setTitle:@"确定" forState:UIControlStateNormal];
    [okBtn setTitleColor:hexColor(333333) forState:UIControlStateNormal];
    [view addSubview:okBtn];
    okBtn.backgroundColor = hexColor(EEEEEE);
    
    chooseBtn.clipsToBounds = YES;
    chooseBtn.layer.cornerRadius = 2;
    chooseBtn.layer.borderColor = hexColor(A6A6A6).CGColor;
    chooseBtn.layer.borderWidth  = 1;
    
    clearBtn.clipsToBounds = YES;
    clearBtn.layer.cornerRadius = 2;
    clearBtn.layer.borderColor = hexColor(A6A6A6).CGColor;
    clearBtn.layer.borderWidth  = 1;
    
    okBtn.clipsToBounds = YES;
    okBtn.layer.cornerRadius = 2;
    okBtn.layer.borderColor = hexColor(A6A6A6).CGColor;
    okBtn.layer.borderWidth  = 1;
    
    quxiaoBtn.clipsToBounds = YES;
    quxiaoBtn.layer.cornerRadius = 2;
    quxiaoBtn.layer.borderColor = hexColor(A6A6A6).CGColor;
    quxiaoBtn.layer.borderWidth  = 1;
    
    chooseBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    clearBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    okBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    quxiaoBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    
    [quxiaoBtn addTarget:self action:@selector(yzViewTapped) forControlEvents:UIControlEventTouchUpInside];
    [chooseBtn addTarget:self action:@selector(chooseBtnClicked) forControlEvents:UIControlEventTouchUpInside];
    [okBtn addTarget:self action:@selector(okBtnClicked) forControlEvents:UIControlEventTouchUpInside];
    [clearBtn addTarget:self action:@selector(clearBtnClicked) forControlEvents:UIControlEventTouchUpInside];
}
- (void)chooseBtnClicked{
    UILabel *label = [self.yzView viewWithTag:800];
    label.text = @"";
    for (LSContactSelectTableViewModel *model in self.chosenArray) {
        model.isSelected = false;
    }
    self.chosenArray = @[];
    LSContactSelectViewController *contactSelectVC = [[LSContactSelectViewController alloc] initWithCompleteHandler:^(LSContactSelectTableViewModel * _Nonnull model) {
        self.chosenArray = @[model];
        if (self.chosenArray && self.chosenArray.count > 0) {
            label.text = model.realname;
        }
    }];
    HEBaseNavController *nav = [[HEBaseNavController alloc] initWithRootViewController:contactSelectVC];
    [self presentViewController:nav animated:true completion:nil];
}
- (void)okBtnClicked{
    LSContactSelectTableViewModel *model = self.chosenArray.firstObject;
    NSString *taskId = [ValidateUtils validateNull:self.selectDict[@"taskId"]];
    if ([taskId isEqualToString:@""]) {
        [MBProgressHUD showTipMessageInWindow:@"taskId为空，请重新选择待办事项"];
        return;
    }
    NSDictionary *param = @{@"token":[ValidateUtils validateNull:[UserInfoModel sharedInstance].token],@"taskId":self.selectDict[@"taskId"],@"id":model.username,@"last":model.realname};
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:true];
    [NetworkUtils requestNOHandleWithMethod:@"POST" URL:rwwt param:param completionHandler:^(id responseObject, NSError *connectionError) {
        [hud hideAnimated:true];
        if (!connectionError) {
            self.chosenArray = @[];
            NSNumber *status = [responseObject objectForKey:@"status"];
            if (status.integerValue == 200) {
                [self yzViewTapped];
                [MBProgressHUD showTipMessageInWindow:[ValidateUtils validateNull:responseObject[@"message"]]];
                [self loadData];
            } else {
                [MBProgressHUD showTipMessageInWindow:[ValidateUtils validateNull:responseObject[@"message"]]];
            }
        } else {
            [MBProgressHUD showTipMessageInWindow:connectionError.localizedDescription];
        }
    }];
}
- (void)clearBtnClicked{
    UILabel *label = [self.yzView viewWithTag:800];
    label.text = @"";
    for (LSContactSelectTableViewModel *model in self.chosenArray) {
        model.isSelected = false;
    }
    self.chosenArray = @[];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setUpHeaderSearchView];
    self.tableViewPage = 1;
    self.title = @"待办事项";
    UIBarButtonItem *approveIconItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"more"] style:UIBarButtonItemStylePlain target:self action:@selector(moreBarButtonItemClick)];
    self.navigationItem.rightBarButtonItem = approveIconItem;
    [self.view addSubview:self.waitForExamineTableView];
//    [self setUpBottomView];
    [self loadData];
    _waitForExamineTableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadData)];
}

- (void)loadData {
    [self.view endEditing:YES];
    self.selectDict = nil;
    self.tableViewPage = 1;
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    NSDictionary *param = @{@"token":[ValidateUtils validateNull:[UserInfoModel sharedInstance].token],@"rows":[NSString stringWithFormat:@"%d",CountPerPage],@"page":[NSString stringWithFormat:@"%d",self.tableViewPage],@"bpmBizTitle":[self.niWenName.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]};
    [NetworkUtils requestNOHandleWithMethod:@"POST" URL:MyWatingApprove param:param completionHandler:^(id responseObject, NSError *connectionError) {
        hud.hidden = YES;
        self.waitForExamineTableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
        [self.waitForExamineTableView.mj_header endRefreshing];
        if (!connectionError) {
            NSArray *dataArray = [responseObject objectForKey:@"data"];
            if (dataArray && dataArray.count > 0) {
                [self.nodataView removeFromSuperview];
                [self.networkErrorView removeFromSuperview];
                 [self.dataArrayM removeAllObjects];
//                for (NSDictionary *dict in dataArray) {
//                    LSWaitForExamineModel *model = [LSWaitForExamineModel waitForExamineModelWithDict:dict];
//                    if (model) [self.dataArrayM addObject:model];
//                }
                [self.dataArrayM addObjectsFromArray:dataArray];
                if (self.dataArrayM.count < self.tableViewPage*CountPerPage) {
                    [self.waitForExamineTableView.mj_footer endRefreshingWithNoMoreData];
                }
                [self.waitForExamineTableView reloadData];
            } else {
                [self.dataArrayM removeAllObjects];
                [self.waitForExamineTableView reloadData];
                 [self.waitForExamineTableView.mj_footer endRefreshingWithNoMoreData];
                [self.networkErrorView removeFromSuperview];
                [self.waitForExamineTableView addSubview:self.nodataView];
            }
        } else {
             [self.waitForExamineTableView.mj_header endRefreshing];
            [self.nodataView removeFromSuperview];
            [self.waitForExamineTableView addSubview:self.networkErrorView];
            self.networkErrorView.tipText = [NSString stringWithFormat:@"%@",connectionError.localizedDescription];
        }
    }];
}

- (void)loadMoreData {
    self.tableViewPage++;
    NSDictionary *param = @{@"token":[ValidateUtils validateNull:[UserInfoModel sharedInstance].token],@"rows":[NSString stringWithFormat:@"%d",CountPerPage],@"page":[NSString stringWithFormat:@"%d",self.tableViewPage]};
    [NetworkUtils requestNOHandleWithMethod:@"POST" URL:MyWatingApprove param:param completionHandler:^(id responseObject, NSError *connectionError) {
        if (!connectionError) {
            NSArray *dataArray = [responseObject objectForKey:@"data"];
            if (dataArray && dataArray.count > 0) {
//                for (NSDictionary *dict in dataArray) {
//                    LSWaitForExamineModel *model = [LSWaitForExamineModel waitForExamineModelWithDict:dict];
//                    if (model) [self.dataArrayM addObject:model];
//                }
                [self.dataArrayM addObjectsFromArray:dataArray];
                if (self.dataArrayM.count < self.tableViewPage*CountPerPage) {
                    [self.waitForExamineTableView.mj_footer endRefreshingWithNoMoreData];
                } else {
                    [self.waitForExamineTableView.mj_footer endRefreshing];
                }
                [self.waitForExamineTableView reloadData];
            } else {
                self.tableViewPage--;
                [self.waitForExamineTableView.mj_footer endRefreshingWithNoMoreData];
            }
        } else {
            self.tableViewPage--;
            [self.waitForExamineTableView.mj_footer endRefreshing];
            [MBProgressHUD showTipMessageInWindow:connectionError.localizedDescription];
        }
    }];
}

#pragma mark - 批量办理点击事件
- (void)examineInBatchesButtonClick:(UIButton *)examineInBatchesButton {
    if (examineInBatchesButton.isSelected) {
        examineInBatchesButton.selected = false;
    } else {
        examineInBatchesButton.selected = true;
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.dataArrayM.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//    LSWaitForExamineTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:LSWaitForExamineTableViewCellID forIndexPath:indexPath];
//    cell.delegate = self;
//    LSWaitForExamineModel *model = self.dataArrayM[indexPath.section];
//    cell.model = model;
//    return cell;
    NiWenListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[[NSBundle mainBundle]loadNibNamed:@"NiWenListCell" owner:nil options:nil]lastObject];
    }
    [cell configDaiBanDict:self.dataArrayM[indexPath.section]];
    cell.xuanzhongbtnclicked = ^(BOOL selected) {
        for (NSInteger i = 0;  i < self.dataArrayM.count; i++) {
            NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:self.dataArrayM[i]];
            dict[@"isSelect"] = @"0";
            [self.dataArrayM replaceObjectAtIndex:i withObject:dict];
        }
        NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:self.dataArrayM[indexPath.section]];
        dict[@"isSelect"] = @"1";
        [self.dataArrayM replaceObjectAtIndex:indexPath.section withObject:dict];
        self.selectDict = self.dataArrayM[indexPath.section];
        [self.waitForExamineTableView reloadData];
    };
    return cell;
}

- (void)selectedButtonWithModel:(LSWaitForExamineModel *)model {
    if (model.isSelected) {
        BOOL isAllSelected = true;
        for (LSWaitForExamineModel *model in self.dataArrayM) {
            if (model.isSelected == false) isAllSelected = false;
        }
        self.selectAllButton.selected = isAllSelected;
    } else {
        self.selectAllButton.selected = false;
    }
    [self.waitForExamineTableView reloadData];
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return LSWaitForExamineTableViewCellHeight;
}

- (UIView *)waitForExamineTableViewHeaderView {
    if (!_waitForExamineTableViewHeaderView) {
        _waitForExamineTableViewHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 45)];
        _waitForExamineTableViewHeaderView.backgroundColor = hexColor(EEEEEE);
        UIView *headerInfoInputView = [[UIView alloc] initWithFrame:CGRectMake(0, 10, ScreenWidth, 35)];
        headerInfoInputView.backgroundColor = UIColor.whiteColor;
        [_waitForExamineTableViewHeaderView addSubview:headerInfoInputView];
        // 人员分类textField
        UITextField *categorySelectBeginnerTF = [[UITextField alloc] initWithFrame:CGRectMake((ScreenWidth-310)/2, 10+7.5, 100, 20)];
        self.categorySelectBeginnerTF = categorySelectBeginnerTF;
        categorySelectBeginnerTF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:11];
        categorySelectBeginnerTF.delegate = self;
        categorySelectBeginnerTF.layer.borderColor = hexColor(dbdbdb).CGColor;
        categorySelectBeginnerTF.layer.borderWidth = 0.5;
        categorySelectBeginnerTF.text = @"   流浪乞讨人员";
        UIImageView *categorySelectBeginnerTFRightViewImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
        categorySelectBeginnerTFRightViewImageView.image = [UIImage imageNamed:@"xiala"];
        categorySelectBeginnerTF.rightView = categorySelectBeginnerTFRightViewImageView;
        categorySelectBeginnerTF.rightViewMode = UITextFieldViewModeAlways;
        [_waitForExamineTableViewHeaderView addSubview:categorySelectBeginnerTF];
        // 搜索内容textField
        UITextField *searchInfoTF = [[UITextField alloc] initWithFrame:CGRectMake((ScreenWidth-310)/2+100+30, 10+7.5, 175, 20)];
        self.searchInfoTF = searchInfoTF;
        searchInfoTF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:11];
        searchInfoTF.delegate = self;
        searchInfoTF.layer.borderColor = hexColor(dbdbdb).CGColor;
        searchInfoTF.layer.borderWidth = 0.5;
        searchInfoTF.placeholder = @"   请输入搜索内容";
        UIImageView *searchInfoTFRightViewImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
        searchInfoTFRightViewImageView.image = [UIImage imageNamed:@"shousuo"];
        searchInfoTF.rightView = searchInfoTFRightViewImageView;
        searchInfoTF.rightViewMode = UITextFieldViewModeAlways;
        [_waitForExamineTableViewHeaderView addSubview:searchInfoTF];
    }
    return _waitForExamineTableViewHeaderView;
}

- (UITableView *)waitForExamineTableView {
    if (!_waitForExamineTableView) {
        _waitForExamineTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, headerSearchViewHeight+5, ScreenWidth, ScreenHeight-SafeAreaTopHeight-headerSearchViewHeight-5)];//-SafeAreaBottomHeight-48
        _waitForExamineTableView.delegate = self;
        _waitForExamineTableView.dataSource = self;
        _waitForExamineTableView.backgroundColor = hexColor(EEEEEE);
        _waitForExamineTableView.separatorInset = UIEdgeInsetsMake(0, ScreenWidth, 0, 0);
        _waitForExamineTableView.allowsSelection = NO;
//        [_waitForExamineTableView registerClass:LSWaitForExamineTableViewCell.class forCellReuseIdentifier:LSWaitForExamineTableViewCellID];
        _waitForExamineTableView.tableFooterView = [UIView new];
//        _waitForExamineTableView.tableHeaderView = self.waitForExamineTableViewHeaderView;
    }
    return _waitForExamineTableView;
}

- (NSMutableArray *)dataArrayM {
    if (!_dataArrayM) {
        _dataArrayM = [[NSMutableArray alloc] init];
    }
    return _dataArrayM;
}

- (NSArray *)chosenArray {
    if (!_chosenArray) {
        _chosenArray = [[NSArray alloc] init];
    }
    return _chosenArray;
}

- (NZKNoDataView *)nodataView {
    if (!_nodataView) {
        _nodataView = [[NZKNoDataView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight-SafeAreaTopHeight) withTip:@"暂无相关信息" andButtonText:nil];
    }
    return _nodataView;
}

- (NZKNetworkErrorView *)networkErrorView {
    if (!_networkErrorView) {
        WS
        _networkErrorView = [[NZKNetworkErrorView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight-SafeAreaTopHeight) withRefreshBlock:^{
            [weakSelf loadData];
        }];
    }
    return _networkErrorView;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
